import { http } from '@/utils/axios/init'
import md5 from 'md5'
import { encrypt } from '@@/utils/index'
export interface BasicResponseModel<T = any> {
  code: number
  msg: string
  data: T
}

// 用户登录
export function login(params) {
  // 密码登录 否则是刷新token登录
  if (params && 'password' in params) {
    params.password = encrypt(md5(params.password))
  }

  return http.request<BasicResponseModel>(
    {
      url: '/uaa/oauth/token',
      method: 'POST',
      params
    },
    {
      isTransformResponse: false,
      joinParamsToUrl: true
      // isMock: true
    }
  )
}

// 获取用户信息
export function getUserInfo() {
  return http.request(
    {
      // url: '/platform/Rest/user/store',
      url: '/api/userInfo',
      method: 'get'
    },
    {
      isMock: true
    }
  )
}

// 获取用户信息
export function getMenus() {
  return http.request(
    {
      url: '/api/menus',
      method: 'get'
    },
    {
      isMock: true
    }
  )
}

// 查询用户权限
export function userAuth(userId) {
  return http.request({
    url: '/system/Rest/user/userAuth',
    method: 'get',
    params: { userId }
  })
}
// 查询组织下的应用
export function getUserOrgApp(params) {
  return http.request({
    url: '/system/Rest/auth/appList',
    method: 'get',
    params
  })
}

// 获取表格数据
export function getTabledata(data) {
  return http.request(
    {
      url: '/api/tabledata',
      method: 'get',
      params: data
    },
    {
      isMock: true
    }
  )
}

// 查询组织用户列表
export function getOrgUserList(params) {
  return http.request<BasicResponseModel>({
    url: '/system/Rest/user/getOrgUserList',
    method: 'GET',
    params
  })
}

// 获取验证码
export function verifyCode() {
  return http.request({
    url: '/uaa/token/verifyCode',
    method: 'get'
  })
}
